package DB;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;

import Entities.GameSpecies;

public class DBSpeciesConnector extends DBConnector{
	static public LinkedList<GameSpecies> getSpeciesList(int offset,boolean isForward){
		String sql;
		if (isForward)
			sql="SELECT * FROM getspecies AS x WHERE id>"+offset+" ORDER BY id ASC LIMIT 100";
		else
			sql="SELECT * FROM (SELECT * FROM getspecies WHERE id<"+offset+" ORDER BY id DESC LIMIT 100) AS x ORDER BY id ASC";
		LinkedList<GameSpecies> speciesList=new LinkedList<GameSpecies>();
		try {
			Connection conn=openConnection();
			Statement stmt=conn.createStatement();
			ResultSet rs=stmt.executeQuery(sql);
			while (rs.next()){
				GameSpecies temp=new GameSpecies(rs.getString("name"),rs.getString("freeBaseID"),rs.getInt("id"));
				speciesList.add(temp);
			}
		    closeConnection(conn);
		}
	     catch (SQLException e) {}
		return speciesList;
	}
}
